home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Utilities / Winter Shell 1.0d2 / Source / Libraries / SystemWindowLib / SystemWindowLib.c next >
Encoding:
C/C++ Source or Header  |  1994-01-11  |  1.6 KB  |  84 lines  |  [TEXT/KAHL]

  1. /* Functions for handling events for system windows.
  2.  
  3.     93/11/17 aih
  4.     - desk accessories are closed in response to CMD_CLOSE
  5.     
  6.     93/11/15 aih
  7.     - added some utility functions
  8.     
  9.     92/03/18 Ari Halberstadt (AIH)
  10.     - Separated from main event handling code. */
  11.     
  12. #include "EventLib.h"
  13. #include "MenuLib.h"
  14. #include "SystemWindowLib.h"
  15. #include "WindowLib.h"
  16.  
  17. Boolean SystemIsActive(void)
  18. {
  19.     WindowPtr front = FrontWindow();
  20.     return(front && WinIsSystem(front) && WinVisible(front));
  21. }
  22.  
  23. WindowPtr SystemWindowActive(void)
  24. {
  25.     return(SystemIsActive() ? FrontWindow() : NULL);
  26. }
  27.  
  28. short SystemWindowRefnum(WindowPtr window)
  29. {
  30.     require(WinIsSystem(window));
  31.     return(WinKind(window));
  32. }
  33.  
  34. void SystemWindowClose(WindowPtr window)
  35. {
  36.     require(! window || WinIsSystem(window));
  37.     if (window)
  38.         CloseDeskAcc(SystemWindowRefnum(window));
  39. }
  40.  
  41. Boolean SystemDoMenu(const MenuPickType *pick)
  42. {
  43.     Str255 name;
  44.     GrafPtr port = NULL;
  45.     Boolean handled = false;
  46.     
  47.     if (pick->cmd == CMD_APPLE) {
  48.         GetPort(&port);
  49.         GetItem(pick->menu, pick->item, name);
  50.         OpenDeskAcc(name);
  51.         SetPort(port);
  52.         handled = true;
  53.     }
  54.     else if (SystemIsActive()) {
  55.         switch (pick->cmd) {
  56.         case CMD_UNDO:
  57.         case CMD_CUT:
  58.         case CMD_COPY:
  59.         case CMD_PASTE:
  60.         case CMD_CLEAR:
  61.             handled = SystemEdit(pick->item - 1);
  62.             break;
  63.         case CMD_CLOSE:
  64.             SystemWindowClose(SystemWindowActive());
  65.             handled = true;
  66.             break;
  67.         }
  68.     }
  69.     return(handled);
  70. }
  71.  
  72. void SystemAdjustMenu(void)
  73. {
  74.     if (SystemIsActive()) {
  75.         MenuCmdEnable(CMD_EDIT);
  76.         MenuCmdEnable(CMD_UNDO);
  77.         MenuCmdEnable(CMD_CUT);
  78.         MenuCmdEnable(CMD_COPY);
  79.         MenuCmdEnable(CMD_PASTE);
  80.         MenuCmdEnable(CMD_CLEAR);
  81.         MenuCmdEnable(CMD_CLOSE);
  82.     }
  83. }
  84.